package com.weixing.mall.provider.controller.front;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoRepeatSubmit;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.core.support.auth.SysAuth;
import com.weixing.mall.core.support.auth.SysInfo;
import com.weixing.mall.provider.api.model.dto.AfterOrderImgDto;
import com.weixing.mall.provider.api.service.OrderServiceRpc;
import com.weixing.mall.provider.model.dto.DefectiveProductSaveDto;
import com.weixing.mall.provider.model.enums.DefectiveProductEunm;
import com.weixing.mall.provider.model.query.DefectiveProductAppQuery;
import com.weixing.mall.provider.model.vo.DefectiveProductAppVo;
import com.weixing.mall.provider.model.vo.front.FrontDefectiveProductDto;
import com.weixing.mall.provider.service.IDefectiveProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName FrontAppDefectiveProductController
 * @Description TODO <br/>
 * @Author gjq
 * @Modified By:
 * @Date 2019/11/13
 * @Version 1.0
 **/
@RestController
@RequestMapping("front/defectiveProduct")
@Api(value = "前端：次品库管理Api",tags = "前端：次品库管理")
public class FrontAppDefectiveProductController extends BaseController {

    @Autowired
    private IDefectiveProductService defectiveProductService;
    @Autowired
    private OrderServiceRpc orderServiceRpc;

    @ApiOperation(value = "入次品库")
    @PostMapping("save")
    @NoRepeatSubmit
    public Result save(@RequestBody FrontDefectiveProductDto defectiveProductSaveDto ,@SysInfo SysAuth auth){
        boolean checkOrder=defectiveProductService.checkOrder(defectiveProductSaveDto);//检查是否为换货订单，且为瑕疵选项
        if(checkOrder){
            AfterOrderImgDto dto=new AfterOrderImgDto();
            dto.setAfterSaleId(defectiveProductSaveDto.getAfterSaleId());
            dto.setImg(defectiveProductSaveDto.getImgurlList());
           Result result= orderServiceRpc.saveAfterOrderImg(dto);
            if(!result.isSuccess()){
                return   ResultUtil.error("图片信息上传错误，请检查！");
            }
        }
        defectiveProductService.createFront(defectiveProductSaveDto,auth);
        return ResultUtil.success();
    }

    @ApiOperation(value = "根据id查找次品库详情")
    @GetMapping("selectDefectiveProductById/{id}")
    public Result selectDefectiveProductById(@PathVariable Long id){
        return ResultUtil.success(defectiveProductService.selectDefectiveProductById(id));
    }

    @ApiOperation(value = "app端次品库列表查询(productStatus是枚举类型)")
    @GetMapping("selectDefectiveProductList")
    public Result selectDefectiveProductList(DefectiveProductAppQuery defectiveProductAppQuery){
        IPage<DefectiveProductAppVo> list = defectiveProductService.selectDefectiveProductList(initMpPage(),defectiveProductAppQuery);
        return ResultUtil.success(list);
    }
    @ApiOperation(value = "app端次品库列表查询(12312321312312312312)")

    @PostMapping("testsave")
    public Result save(Long orderId,Integer type,Long uid,String remark){
        defectiveProductService.createRpc(orderId,type,uid,remark);
        return ResultUtil.success();
    }

}
